﻿#pragma once

#include <iostream>
#include <string>
#include <tuple>

// 用于C风格的可变参数，C++11之前常用
#include <cstdarg>

// C++11引入 initializer_list，用于处理可变数量的相同类型参数
#include <initializer_list>

// C++17引入 utility，用于 std::forward 等
#include <utility>

// type_traits 用于 std::is_same, 
// std::is_base_of, 
// std::is_enum, 
// std::is_union,
// std::is_class,
// std::is_pointer,
// std::is_integral_v,
// std::is_floating_point_v  ...
#include <type_traits>


// 控制语句与函数
extern void test_conditional_statement();
extern void test_loop_statement();
extern void test_jump_statement();

// 函数的局部变量部分结构体定义
struct CountStruct {
	int count = 0;
	CountStruct() = default; // 不写这行默认为 CountStruct() = delete;
	CountStruct(int count) : count(count) {}
	CountStruct(const CountStruct& out_struct) {
		// 注意不写这个函数则默认拷贝构造函数为 CountStruct(const CountStruct&) = delete;
		count = out_struct.count;
	}
	CountStruct(CountStruct&& out_struct) noexcept {
		// noexcept 说明移动构造函数不会抛出异常
		this->count = std::move(out_struct.count);
		out_struct.count = 0; // 可选的：重置 out_struct 的状态
	}

	const int& value() const {
		return count;
	}
	void print() const {
		std::cout << "current count: " << count << std::endl;
	}

	const int& operator()() const { // 比较奇葩
		return count;
	}
	int operator=(int out_count) {
		count = out_count;
		return count;
	}
	CountStruct& operator=(const CountStruct& out_struct) noexcept {
		if (this != &out_struct) // 检查自赋值
			count = out_struct.count;
		return *this;
	}
	CountStruct& operator=(CountStruct&& out_struct) noexcept {
		if (this != &out_struct) { // 检查自赋值
			count = std::move(out_struct.count);
			out_struct.count = 0; // 可选的：重置 out_struct 的状态
		}
		return *this;
	}
	bool operator==(const CountStruct& out_struct) const {
		//return *this == out_struct // 无限递归
		return this == &out_struct;
	}
	bool operator!=(const CountStruct& out_struct) const {
		//return *this != out_struct // 无限递归
		return this != &out_struct;
	}
	bool operator<(const CountStruct& out_struct) const {
		return count < out_struct.count;
	}
	bool operator<=(const CountStruct& out_struct) const {
		return count <= out_struct.count;
	}
	bool operator>(const CountStruct& out_struct) const {
		return count > out_struct.count;
	}
	bool operator>=(const CountStruct& out_struct) const {
		return count >= out_struct.count;
	}
	CountStruct operator+(const CountStruct& out_struct) const {
		CountStruct temp = *this;
		temp.count += out_struct.count;
		return temp;
	}
	CountStruct operator-(const CountStruct& out_struct) const {
		CountStruct temp = *this;
		temp.count -= out_struct.count;
		return temp;
	}
	CountStruct operator*(const CountStruct& out_struct) const {
		CountStruct temp = *this;
		temp.count *= out_struct.count;
		return temp;
	}
	CountStruct operator/(const CountStruct& out_struct) const {
		CountStruct temp = *this;
		temp.count /= out_struct.count;
		return temp;
	}
	CountStruct operator%(const CountStruct& out_struct) const {
		CountStruct temp = *this;
		temp.count %= out_struct.count;
		return temp;
	}
	CountStruct operator+=(const CountStruct& out_struct) {
		count += out_struct.count;
		return *this;
	}
	CountStruct operator-=(const CountStruct& out_struct) {
		count -= out_struct.count;
		return *this;
	}
	CountStruct operator*=(const CountStruct& out_struct) {
		count *= out_struct.count;
		return *this;
	}
	CountStruct operator/=(const CountStruct& out_struct) {
		count /= out_struct.count;
		return *this;
	}
	CountStruct operator%=(const CountStruct& out_struct) {
		count %= out_struct.count;
		return *this;
	}

	// 前置版本的 ++ 和 --
	CountStruct& operator++() {
		++count;
		return *this;
	}
	CountStruct& operator--() {
		--count;
		return *this;
	}
	CountStruct& operator+=(int n) {
		count += n;
		return *this;
	}
	CountStruct& operator-=(int n) {
		count -= n;
		return *this;
	}
	//后置版本的 ++ 和 --
	CountStruct operator++(int) {
		CountStruct temp = *this;
		++count;
		return temp; // 局部变量不能返回引用
	}
	CountStruct operator--(int) {
		CountStruct temp = *this;
		--count;
		return temp;
	}
};
extern void test_local_variable();


// 函数可变参数
extern void test_variadic_parameters();
extern void test_multiple_types();



// 宏定义
#define print_start(str) std::cout << " ----------------- " << str << " Start ------------------------\n";
#define print_end(str) std::cout << " ----------------- " << str << " End ------------------------\n\n\n";


//一些运算符不能被重载: 例如，:: (作用域解析运算符)、.*和 ->* (成员指针访问运算符)、 ? : (条件运算符)以及 sizeof(大小运算符) 不能被重载。

